Skip to content

Main gets a lighter main-menu slot count, stronger save tests and save tickets that match the code - #39

Merged
redcode9 merged 13 commits into
features/state-of-the-art-development/mainfrom
features/state-of-the-art-development/wip/save-store
Nov 16, 2026
Merged

redcode9 merged 13 commits into
features/state-of-the-art-development/mainfrom
features/state-of-the-art-development/wip/save-store

Conversation

@redcode9

Copy link
Copy Markdown
Owner

Review-fix round for wip/save-store. The branch was fast-forwarded to main 391f5e9 first, so this PR holds eleven commits: one PSP code change in source/src/gui.c with its host test, two test-only changes, one line in a check script and seven docs commits. save_store.c, save_format.c, memory.c and main.c do not change.

What was wrong and what changed:

  • SAV-1.5 and the code did not agree, and nobody had settled it (c8bb36e, c184a77). The ticket said that at startup two No answers to the unreadable-save questions open the menu. That holds for a start from game.gba or the browser. From a launcher (ROM in argv) the emulator quits instead (source/src/main.c:2410-2419), as a failed launcher load already did before this branch. PR Main gets the save store: safe .sav reads and writes, pre-link copies #24 listed the difference under "To know before merging" and was merged, but docs/wip/save-store.md still said «da confermare nella PR», and the SAV-1 goal and docs/saves.md still said two No answers go back to the game list. SAV-1.5, the SAV-1 goal, docs/saves.md and the wip note now describe both startup cases. c184a77 rewraps the docs/saves.md paragraph, which had a 96-column line. tests/test_startup.py already checks both behaviours, so no code changed.
    • To check before merging: c7 was settled by accepting the quit, the docs-only option the verifier proposed, under the user's approval of the review-fix list on 2026-11-16. The tickets record it as a decision of that date. To revert it instead, call menu() at source/src/main.c:2419, as the game.gba path does, and update tests/test_startup.py:189.
  • Each return to the main menu cost about 121 sceIo calls, not the 11 stats the comment and the UI-11.1 text promise (845d445, 53a4fc1). menu_status_count_states() (ui-ge) counted the slots with savestate_file_exists(), which runs save_store_recover() first (save-store). For an empty slot, recovery checks three names, and each missing name costs a stat plus a folder open and close, then removes the .tmp: about 11 calls per slot, on the first entry and on every Back from a submenu. Neither branch did this alone; the two met when main was merged into ui-ge. A new static savestate_file_stat() does the one sceIoGetstat. savestate_file_exists() recovers and then calls it, and the count uses savestate_file_stat() directly, so it is back to 11 stats. The Load slot backup check, the benchmark arm and every load still recover first. A comment records the trade-off: a save cut mid-write counts as empty on the main-menu row until a load recovers it. tests/test_save_io.py gains test_main_menu_counts_slots_without_recovery, which cuts the three functions out of gui.c, runs them against counting stubs and checks 11 stats, no recovery and the right counts. 53a4fc1 widens the guard in scripts/check-menu-layout.sh that keeps file system calls out of the per-frame menu_draw_main_status(), so a savestate_file_stat() call there now fails the check too.
  • No test fed the save store a write that returns 0, the only failure value the real sceIo binding gives (e721266). save_io_write returns 0 on a full Memory Stick, but tests/fake_store_io.c returned -1, so the guard at save_store.c:152 that stops the write loop on a 0 could regress with every test still green. That regression would freeze the emulator on every save to a full Memory Stick. The fake now returns 0 when the device is full and keeps -1 for a bad handle, so negative counts stay covered. It also asserts that nothing writes again after a 0 on the same open file (a took_nothing field, reset on each open_write), so the regression fails the test at once instead of hanging it. No production code changed.
  • The savestate repair test could not tell the value in use before the load from a hard-coded default, and never loaded a state of type NONE (97790f3). Its fallback values were SRAM, 64 KiB, 64 KiB Flash and 512 B EEPROM, the same as the obvious defaults. The fallback in tests/test_save_format.c is now Flash, 32 KiB SRAM, 128 KiB Flash and 8 KiB EEPROM, and the asserts follow. A state with SAVE_TYPE_NONE, saved before the game's first backup access, must now load unchanged. The SRAM size had the same gap and is covered too. Tests only.
  • SAV-1.6, SAV-1.7 and SAV-2.4 still said the runtime log stays at v5, and SAV-1.7 said its event was missing (560700b, 3db2bcf). runtime_log.h writes version 6 and memory.c logs SAVESTATE_REPAIR. The three tickets now say v6, and SAV-1.7 names RUNTIME_LOG_EVENT_SAVESTATE_REPAIR. 3db2bcf drops the last sentence of SAV-1.6, about moving the event into ENG-1.6's bump if the rule were refused: that bump has happened. The historical sentence «È il primo tipo di evento nuovo dalla v5» stays.
  • The wip note said SAV-2.6 reached main in b5cffbf, which is the ROM link check fix (ce49a51). The save test ROM (77ec1d7) reached main with dbab178, which the note now cites.
  • EXT-1.2 said the eeprom8k_wfirst target writes a whole generation before any read (3961356). tests/save-rom/source/main.c writes one block (3Fh) with an 81-unit DMA on every boot, because the ROM cannot tell an empty chip without reading it and a whole generation would destroy the one read_back checks. Its «Cosa» now says so, notes that the text said «una generazione» until 2026-11-16, and says later boots run as eeprom8k plus that write. The EXT-1.2 status line in the wip note records the change. The ROM code is unchanged.
  • The changelog called the menu "Link" (a59a3e4). The category is "Link Cable" in the menu and in the other docs. Both Unreleased lines about the pre-link copy now say Link Cable, rewrapped to 76 columns.

Tickets whose status changed:

  • No ticket was ticked or unticked.
  • SAV-1.5: its «Cosa» and the SAV-1 goal now describe the launcher quit, and the wip status line records the difference as accepted on 2026-11-16 in place of «da confermare nella PR». The checkbox stays empty: it still needs its PSP session.
  • EXT-1.2: its «Cosa» and status line now describe the one-block write. The checkbox stays empty: it still needs make test-roms with an ARM compiler and its PSP sessions.
  • SAV-1.6 and SAV-1.7 stay ticked and SAV-2.4 stays open; only their text changed (v6, the event name, the dropped fallback).
  • The «Dipende da» line of docs/wip/save-store.md cites dbab178 for SAV-2.6. No wait changed and no story became startable.

Tests on this host (clang with the freestanding host shim; UBSan in trap mode):

  • test_save_store, with zlib's crc32.c built as an object in place of -lz: passes, plain and with UBSan. With save_store.c:152 changed from count <= 0 to count < 0, both builds now stop on the fake's assert. Before this PR the same mutant passed, and with a fake that returned 0 it hung.
  • test_save_format: passes, plain and with UBSan. Five mutants of save_format_sanitize now fail both builds: the type check as >=, and the type, SRAM, Flash and EEPROM fallbacks hard-coded to SRAM, 64 KiB, 64 KiB and 512.
  • tests.test_save_io: OK (2 tests), plain and with UBSan. The new test fails when the count calls savestate_file_exists() for the numbered slots or for the auto slot, when recovery is dropped from savestate_file_exists(), and when the auto slot is hard-coded.
  • scripts/check-menu-layout.sh: passes on HEAD. With a gui.c mutant that calls savestate_file_stat(0) inside menu_draw_main_status(), the new pattern fails (rc=1) and the old one passed (rc=0).
  • scripts/check-tree.sh (messages, menu layout, runtime lifecycle, video lifecycle, performance, script syntax, forbidden names, module tests, source tree), plus check-menu-layout.sh, check-lifecycle.sh, check-performance.sh and check-messages.sh on their own, run from CR-stripped copies with PYTHON=python: all pass.
  • tests.test_browser_text, test_input_shortcuts, test_startup, test_theme_boot, test_toast_draw and test_ui_golden under the shim: all pass except test_startup.test_diagnostic_autorun_glue and test_ui_golden.test_screens_match_golden_hashes. Both fail the same way on a clean export of 391f5e9, so they come from the shim environment, not from this PR (the autorun test fails because the shim has no strcat).
  • The reviewer reran the save tests and the mutants on a git archive export of the branch and got the same results.
  • git diff --check 391f5e9..HEAD is clean. No message table changed, and every changed file keeps its line endings.
  • No Makefile change is needed: test_save_io.py is already in make test-tools, and test_save_format and test_save_store are already in HOST_TESTS and the sanitize lists.
  • CI will run make check, make test-sanitize, make check-cbmc and both PSP builds on this PR.

Not verified here:

  • make check, make test-sanitize with gcc and ASan, make check-cbmc and the PSP builds: this machine has no make, gcc or PSPDev. The gui.c change is PSP code built with -Werror. It was read for unused statics, unused locals and declaration order, but not compiled for the PSP. CI has to confirm it.
  • test_memory_backup, test_eeprom and test_perf_dma_probe link the changed fake but need memory.c and the PSP SDK headers, so they did not run here. By reading they are safe: they reach the fake only through save_store_append, which stops after the first 0, and open_write resets took_nothing before any retry. test_memory_backup's retry on a full device (test_failed_write_stays_pending) depends on that reset. CI has to confirm all three.
  • No hardware run. How long a return to the main menu takes on a PSP-1000 Memory Stick with a full dir_state is unmeasured; it belongs in the UI-11.1 hardware session. SAV-1.5 and EXT-1.2 still need their PSP sessions.

Files of other branches touched (rule 5):

  • source/src/gui.c: menu_status_count_states() is ui-ge's UI-11.1 code. The change splits save-store's savestate_file_exists() into one new static helper and changes the two call sites in the count. Nothing else in ui-ge's code changed.
  • scripts/check-menu-layout.sh (ui-ge): one line, the grep pattern at line 82, now sceIo|savestate_file_(exists|stat)|get_savestate_info.
  • CHANGELOG.md (shared): only this branch's two Unreleased lines about the pre-link copy.
  • docs/BACKLOG.md (shared): only this branch's tickets: the SAV-1 goal, SAV-1.5, SAV-1.6, SAV-1.7, SAV-2.4 and EXT-1.2.

Skipped, with the reason:

  • The second review found no blockers and no minors, and left three test-strength nits. The code they cover is correct, so they are left for a later round:
    • In test_sanitize_repairs_each_field each fallback value is now the other valid constant, so mutants that hard-code SRAM_32K, FLASH_128K or EEPROM_8K still pass. A second run with SRAM, 64 KiB, 64 KiB and 512 as the values in use would catch them.
    • test_main_menu_counts_slots_without_recovery does not check that savestate_file_exists() recovers before it stats. Its recovery stub changes nothing, so a version that stats first passes. A stub that makes a cut slot appear on recovery would catch it.
    • Dropping the took_nothing reset in open_write passes test_save_store; only test_memory_backup's retry reaches it, and that runs in CI only.
  • Two commit bodies have one 73-column line each (c8bb36e, 560700b). Rewording them needs a rebase, and the review advised against rebasing a branch that is on origin (rule 3), so they stay. The later commit bodies are 72 columns or fewer.
  • CHANGELOG.md Unreleased has two «### Fixed» headings. They come from the open-BIOS, ui-ge and ui-foundation commits, not from this branch, so they are left for their owners.
  • The two shim-only test failures above predate this PR and were not investigated.
  • No new CHANGELOG.md entry: the main-menu slot count and the recovery it no longer runs are both new in Unreleased, so no released build had the extra calls. The other fixes are tests and docs.

The branch stays open, so docs/wip/save-store.md stays.

SAV-1.5 said two No answers at startup open the menu. From game.gba or
the browser they do; from a launcher (ROM in argv) they quit, as a failed
launcher load already did. Accepted on 2026-11-16: the ticket, the SAV-1
goal and docs/saves.md now say so.
Since savestate_file_exists() recovers a cut save first, the Save and
Load row cost about ten sceIo calls per empty slot, some 121 each time
the main menu opened. The count now stats each slot once; the Load page,
the benchmark and every load still recover first.
save_io_write returns 0 on ENOSPC, but the fake returned -1, so no test
fed save_store a 0 and the guard against spinning on a full Memory Stick
could go unnoticed. The fake now returns 0 and asserts that nothing
writes again after it, so a regression fails instead of hanging.
The repair test's fallback values matched the obvious defaults, so a
sanitize that ignored them passed, and no valid state had type NONE.
The fallback now differs from every default, and a NONE state must load
unchanged.
SAV-1.6, SAV-1.7 and SAV-2.4 still said the format stays v5, and SAV-1.7
that its event was missing. The tree logs SAVE_LOAD, SAVESTATE_REPAIR and
SAVE_WRITE in format 6, ENG-1.6's version.
The note gave b5cffbf, the ROM link check fix; the save type test ROM
(SAV-2.6) reached main with dbab178.
EXT-1.2 said the target writes a whole generation before any read. It
writes one block (3Fh) on every boot, since a generation would destroy
what read_back checks, and after the first boot it runs as eeprom8k plus
that write.
The main menu now counts its state slots with savestate_file_stat(),
so the guard that keeps file system calls out of
menu_draw_main_status() looks for that name too.
The ticket already says the format stays at v6, the version ENG-1.6
bumped to, so the fallback to that bump no longer applies.
gui.c: the main menu's slot count comment now says both when it is
counted (also after an AUTO state write, from main) and why it skips
recovery (this branch). tests/test_save_io.py keeps main's trace save
test, which calls the module-level build_and_run, and this branch's
slot count test.
@redcode9
redcode9 merged commit 6afd012 into features/state-of-the-art-development/main Nov 16, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant